//-----------------------------------------------------------------------------
//クラス名：ClubNL.java
//所    属：H3A1 04
//名    前：大瀬碩
//説    明：クラブ選択で選ばれたクラブの情報を表示する
//-----------------------------------------------------------------------------
package club;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

//@WebServlet("/ClubNL")
public class ClubNL extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

    public ClubNL() {
        super();
        
    }


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html; charset=UTF-8");
	 	
	 	HttpSession session = request.getSession(true);
	 	
	 	//DB接続
	 	ServletContext context = this.getServletContext();
		String path = context.getRealPath("/WEB-INF/connect.properties");
		
		InputStream in = new FileInputStream(path);
		Properties properties = new Properties();
		properties.load(in);
		in.close();
	    
	    Connection conn = null;
	    String url = properties.getProperty("key1");
	    String user = properties.getProperty("key2");
	    String password = properties.getProperty("key3");
	    
	    String i = request.getParameter("club");
	    session.setAttribute("sel_club", i);
	    
	    try {
		      Class.forName("com.mysql.jdbc.Driver").newInstance();
		      conn = DriverManager.getConnection(url, user, password);
		          
		          //DBから情報取得
			      Statement stmt = conn.createStatement();
			      String sql = "SELECT * FROM club_detail WHERE club_id = "+i;
			      ResultSet rs = stmt.executeQuery(sql);
			      
			      while(rs.next()){
			    	  request.setAttribute("jisseki",rs.getString("jisseki"));
			    	  request.setAttribute("hitokoto",rs.getString("hitokoto"));
			      }
		      rs.close();
		      stmt.close();
		    }catch (ClassNotFoundException e){
		    	
		    }catch (SQLException e){
		      
		    }catch (Exception e){
		    	
		    }finally{
		      try{
		        if (conn != null){
		          conn.close();
		        }
		      }catch (SQLException e){
		        
		      }
		    }
		    
		    RequestDispatcher rd = request.getRequestDispatcher("ClubNL.jsp");
			rd.forward(request,response);
	}
}
